package czx.wt.util.response;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @Description: 类作用描述
 * @Author: ChenZhiXiang
 * @CreateDate: 2018/12/20 0020 14:16
 * @Version: 1.0
 */
public class Resp {

    private static final Logger logger = LoggerFactory.getLogger(Resp.class);

    public static void outResp(HttpServletResponse response,String msg) {
        PrintWriter out = null;
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            //设置编码
            response.setCharacterEncoding("UTF-8");
            //设置返回类型
            response.setContentType("application/json");
            out = response.getWriter();
            //输出
            out.println(msg);
        } catch (Exception e) {
            logger.error("响应json信息出错", e);
        } finally {
            if (null != out) {
                out.flush();
                out.close();
            }
        }
    }
}
